package com.nbsaas.boot.project.controller;

import com.nbsaas.boot.project.api.apis.ReceiptApi;
import com.nbsaas.boot.project.api.domain.request.ReceiptRequest;
import com.nbsaas.boot.project.api.domain.request.ReceiptSearch;
import com.nbsaas.boot.project.api.domain.response.ReceiptResponse;
import com.nbsaas.boot.project.api.domain.simple.ReceiptSimple;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收款单控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/receipt")
public class ReceiptController {


    @Resource
    private ReceiptApi receiptApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("receipt:search")
    @PostMapping("/search")
    public PageResponse<ReceiptSimple> search(@RequestBody ReceiptSearch request) {
        return receiptApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("receipt:list")
    @PostMapping("/list")
    public ListResponse<ReceiptSimple> list(@RequestBody ReceiptSearch request) {
        return receiptApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("receipt:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<ReceiptResponse> create(@RequestBody @Validated(AddOperator.class) ReceiptRequest request) {
        return receiptApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("receipt:update")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<ReceiptResponse> update(@RequestBody @Validated(UpdateOperator.class) ReceiptRequest request) {
        return receiptApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("receipt:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) ReceiptRequest request) {
        return receiptApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("receipt:view")
    @PostMapping("/view")
    public ResponseObject<ReceiptResponse> view(@RequestBody @Validated(ViewOperator.class) ReceiptRequest request) {
        return receiptApi.view(request);
    }
}